<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
    <head>
        <title>Student Registration Form</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <script type="text/javascript">
            function validate_required(field, alertext){
                with(field){
                    if(value==null||value==""){
                        alert(alertext);
                        return false;
                    }else{
                        return true;
                    }
                }
            }
            function validate_user(field,alertext)
            {
                with(field)
                {
                    var alphaExp =/^[a-z0-9_-]{3,15}$/;
                    if(field.value.match(alphaExp))
                    {
                        return true;
                    }
                    else
                    {
                        alert(alertext);
                        return false;
                    }
                }	
            }
            function validate_text(field,alertext)
            {
                with(field)
                {
                    var alphaExp = /^[a-zA-Z ]+$/;
                    if(field.value.match(alphaExp))
                    {
                        return true;
                    }
					
                    else
                    {
                        alert(alertext);
                        return false;
                    }
                }	
            }

            function validate_id(field,alertext)
            {
                with(field)
                {
                    var alphaExp =/^[0-9]{4}[-][0-9]{2}[-][0-9]{3}[-][0-9]{3}$/;
                    if(field.value.match(alphaExp))
                    {
                        return true;
                    }
                    else
                    {
                        alert(alertext);
                        return false;
                    }
                }	
            }
            function validate_pwd(field,alertext)
            {
                with(field)
                {
                    var alphaExp =/^[A-Za-z]\w{4,13}[A-Za-z]$/;
                    if(field.value.match(alphaExp))
                    {
                        return true;
                    }
                    else
                    {
                        alert(alertext);
                        return false;
                    }
                }	
            }
            function disable(){
                document.getElementById('course').disabled=true;
                document.getElementById('course_year').disabled=true;
            }
            function enable(){
                document.getElementById('course').disabled=false;
                document.getElementById('course_year').disabled=false;
            }
            function removeoption(){
                document.getElementById('course_year').options[3].disabled=true;
            }
            function confirm_pwd() {
                var pwd=document.getElementById('usr_pwd');
                var repwd=document.getElementById('usr_repwd');
                if (pwd.value!=repwd.value)
                {
                    alert("Passwords do not match");
                    return false;
                }
                else {
                    return true;
                }
            }
            function validate_form(thisform){
                with(thisform){
                    if(validate_required(id, "Enter your registered id")==false||validate_id(id, "Enter your id correctly")==false){
                        id.focus();
                        return false;
                    }
                    if(validate_required(first_name, "Enter your first name")==false||validate_text(first_name, "Enter your first name correctly")==false){
                        first_name.focus();
                        return false;
                    }
                    if(validate_required(last_name, "Enter your last name")==false||validate_text(last_name, "Enter your last name correctly")==false){
                        last_name.focus();
                        return false;
                    }
                    if(validate_required(email, "Enter your registered email")==false){
                        email.focus();
                        return false;
                    }
                    if(validate_required(usr_name, "Enter your user name")==false||validate_user(usr_name, "Enter a valid user name")==false){
                        usr_name.focus();
                        return false;
                    }
                    if(validate_required(usr_pwd, "Enter your password")==false||validate_pwd(usr_pwd, "Enter a valid password")==false){
                        usr_pwd.focus();
                        return false;
                    }
                    if(validate_required(usr_repwd, "Re enter password")==false||confirm_pwd()==false){
                        usr_repwd.focus();
                        return false;
                    }
                    if(validate_required(role, "Select your role")==false){
                        role.focus();
                        return false;
                    }
                    if(document.getElementById('role').value.match('student')){                        
                        if(validate_required(course, "Select your course")==false){
                            course.focus();
                            return false;
                        }
                        if(validate_required(course_year, "Select your course year")==false){
                            course_year.focus();
                            return false;
                        }
                    }
                }
            }  

        </script>

    </head>
    <body>
        REGISTRATION
        <form name="myform" method="post" action="registered_users_db.jsp" onsubmit="return validate_form(this)">
            <table>
                <tr>
                    <td>
                        Registered Id
                    </td>
                    <td>
                        <input type="text" name="id">
                    </td>
                </tr>
                <tr>
                    <td>
                        First Name
                    </td>
                    <td>
                        <input type="text" name="first_name">
                    </td>
                </tr>
                <tr>
                    <td>
                        Last Name
                    </td>
                    <td>
                        <input type="text" name="last_name">
                    </td>
                </tr>
                <tr>
                    <td>
                        Registered Email
                    </td>
                    <td>
                        <input type="email" name="email">
                    </td>
                </tr>
                <tr>
                    <td>
                        Create your username
                    </td>
                    <td>
                        <input type="text" name="usr_name">
                    </td>
                </tr>
                <tr>
                    <td>
                        Create a password
                    </td>
                    <td>
                        <input type="password" id="usr_pwd" name="usr_pwd">
                    </td>
                </tr>
                <tr>
                    <td>
                        Confirm your password
                    </td>
                    <td>
                        <input type="password" id="usr_pwd" name="usr_repwd">
                    </td>
                </tr>
                <tr>
                <tr>
                    <td>
                        Role
                    </td>
                    <td>
                        Student <input type="radio" name="role" id="roles" value="student" onclick="enable()" checked>
                        Faculty <input type="radio" name="role" id="rolef" value="faculty" onclick="disable()">
                    </td>
                </tr>
                <td>
                    Course
                </td>
                <td>
                    <select name="course" id="course">
                        <option value="">Select</option>
                        <option value="MCA">MCA</option>
                        <option value="MBA" onclick="removeoption()">MBA</option>
                        <option value="MSC" onclick="removeoption()">MSC</option>
                    </select>
                </td>
                </tr>
                <tr>
                    <td>
                        Course Year
                    </td>
                    <td>
                        <select name="course_year" id="course_year">
                            <option value="">Select</option>
                            <option value="I">I</option>
                            <option value="II">II</option>
                            <option value="III">III</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" align="center">
                        <input type="submit" value="Register" />
                        <input type="reset" value="Clear" />
                    </td>
                </tr>
            </table>
        </form>
    </body>
</html>
